<%-- 
    Document   : plannig
    Created on : 8-lug-2014, 10.41.59
    Author     : Mark
--%>

<%@page import="java.util.LinkedList"%>
<%@page import="it.evento.Events"%>
<%@page import="it.evento.EventPrintable"%>
<%@page import="java.util.List"%>
<%@page import="it.evento.utils.genpage.Article"%>
<%@page import="it.evento.utils.genpage.ArticleRow"%>
<%@page import="it.evento.utils.genpage.RowCell"%>
<%@page import="it.evento.Users"%>
<%@page import="it.evento.utils.genpage.BlogPost"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%
    boolean isLoggedUser = false;
    Users loggedUser = null;

    if (session.getAttribute("loggedUser") != null) {
        loggedUser = (Users) session.getAttribute("loggedUser");
        isLoggedUser = true;
    } else {
        isLoggedUser = false;
    }
%> 


<!DOCTYPE html>
<html dir="ltr" lang="it-IT">
    <head>
        <title>EvenTO</title>

        <jsp:include page="html/metadata.jsp" flush="true" />
        <script src="js/jquery.ui.min.js"></script>

        <script>
             $(function() {
                $("#datepickerstart").datepicker();
                document.getElementById('btnAddEvent').disabled=true;
                /* TYPE EVENT*/
                $.getJSON("Controller?type=getType", function(data) {
                    var items = [];
                    $.each(data, function(key, val) {
                        items.push("<option value='" + val.id + "'>" + val.label + "</option>");
                    });

                    $("<select/>", {
                        name: "eventType",
                        html: items.join("")
                    }).appendTo("#eventTypeDiv");

                });
                /* /TYPE EVENT*/
                
                /* EVENTI DISPONIBILI */
                $('#btnSearchEvents').click(function(e) {
                    e.preventDefault();
                    $("#eventPresent").empty();//svuota la div dove ci sono i risultati precedenti
                    
                    var sendData={type: "searchEventPalnnig",
                                evStartDate: $('input[name="evStartDate"]').val(),                               
                                eventType: $('select[name="eventType"]').val()
                            };

                    $.post("Controller",sendData,
                    function(data) {
                        if (data.status === 0) {
                            
                            //$('#outputMsg').html("<ul>"+data.message+"</ul>"); 
                            
                            var obj = jQuery.parseJSON( data.message );
                            var items = [];
                            
                            $.each(obj, function(key, val) {
                                items.push("<option value='" + val.id + "'>" + val.label + "</option>");
                            });

                            $("<select/>", {
                                name: "eventPresent",
                                html: items.join("")
                            }).appendTo("#eventPresent");

                        }
                    },
                            'json');

                            document.getElementById('btnAddEvent').disabled=false;
                });
                /* EVENTI DISPONIBILI */
                
            });
        </script>
    </head>
    <body>
        <div id="evento-main">
            <!-- header -->
            <jsp:include page="html/header.jsp" flush="true" />
            <!-- /header -->

            <!-- top-menu -->
            <%@include file="html/top-menu.jsp" %>
            <!-- /top-menu -->

            <div class="evento-sheet clearfix">
                <div class="evento-layout-wrapper">
                    <div class="evento-content-layout">
                        <div class="evento-content-layout-row">
                            <div class="evento-layout-cell evento-content">
                                <% if(request.getQueryString()== null){ %>
                                    <%=
                                    new Article()
                                       .setTitle("Autenticazione Google Calendar")
                                       .setContent("<table style='border:0px'><tr>"
                                                        +"<form action='OAuthController?authenticate' method='POST'> "  
                                                            +"Acconsenti al trattamento dei dati presenti sul tuo Calendario Google?"
                                                            +"<br/>"
                                                            +"<td style='border:0px'><input type='submit'  value='Consenti' class='evento-button'/></td>"                             
                                                        +"</form>"
                                                        +"<form action='index.jsp' method='POST'>"                                         
                                                            +"<td style='border:0px'><input type='submit'  value='Nega' class='evento-button'/></td>"
                                                    +"</tr> </table>")
                                        .print()           
                                     %>
                                
                                <%}else{
                                    if(request.getQueryString().contains("auth")){                                
                                        if(request.getParameter("auth").toString().equals("ok")){
                                %>
                               
                                     <%=
                                    new Article()
                                       .setTitle("Ricerca Evento")
                                       .setContent("<form id='searchEvents'>"                                                                                    
                                                        +"Data: <input type='text' name='evStartDate' id='datepickerstart'/>"
                                                        +"Tipologia Evento:"
                                                        +"<div  id='eventTypeDiv'></div>"                      
                                                        +"<br/>"
                                                        +"<input type='submit'  id='btnSearchEvents' value='Trova' class='evento-button'/>" 
                                                        +"</form>")
                                        .print()           
                                     %>
                                     
                                       <%=
                                    new Article()
                                       .setTitle("Aggiungi al Calendario")
                                       .setContent("<form action='CalendarController?type=createEvent' method='POST'>"
                                                        +"Eventi Disponibili:"                                    
                                                        +"<br/>"
                                                        +"<div id='eventPresent'></div>"
                                                        +"<input type='submit' id='btnAddEvent' value='Aggiungi' class='evento-button'/>"
                                                    +"</form>"
                                                    + "<br>"
                                                    +"<div  id='outputMsg'></div> ")                                                     
                                        .print()           
                                     %>
                               
                                    <%}}}%>
                                   
                                    
                                    <br/>
                                    <br/>
                                    <center>
                                        <iframe src="https://www.google.com/calendar/embed?showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;showTz=0&amp;height=300&amp;wkst=1&amp;bgcolor=%23666666&amp;src=<%= request.getParameter("Calendar")%>&amp;color=%236B3304&amp;ctz=Europe%2FRome" width="800" height="600" frameborder="0" scrolling="no"></iframe>
                                    </center>
                               
                            </div>

                            <!-- sidebar -->
                            <jsp:include page="html/sidebar.jsp" />
                            <!-- /sidebar -->

                        </div>
                    </div>
                </div>

                <!-- footer -->
                <%@include file="html/footer.jsp" %>
                <!-- /footer -->

            </div>
        </div>
    </body>
</html>
